package com.hw.nio.netty.rpc.test;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class UserServiceImpl implements UserService {
    Random random = new Random(1);

    @Override
    public User getUser(Integer id)  {
        User user = newUser(1).get(0);
        user.setId(id);
        try {
            Thread.sleep(random.nextInt(500));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return user;
    }

    public static void main(String[] args) {
        Random random = new Random(1);
        for (int i = 0; i < 100; i++) {
            System.out.println(random.nextInt(100));
        }
    }

    @Override
    public List<User> findUser(String name) {
        return newUser(10);
    }

    private static List<User> newUser(int count) {
        List<User> list = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            User user = new User();
            user.setId(i);
            user.setName("用户名" + i);
            user.setCreateTime(new Date());
            user.setSex("66");
            list.add(user);
        }
        return list;

    }
}
